package shopping.dao.impl;

import shopping.bean.Clothes;
import shopping.bean.Goods;
import shopping.dao.GoodsDao;

import java.util.List;

public class GoodsDaoImp extends BaseDao implements GoodsDao {


    @Override
    public Goods queryGoodsById(Integer id) {
        String sql = "select `id` , `name` , `kind` , `price` , `sales` , `img_path` imgPath from goods where id = ?";
        return queryForOne(Goods.class,sql,id);
    }

    @Override
    public List<Goods> queryGoodss() {
        String sql = "select `id` , `name` , `kind` , `price` , `sales` , `img_path` imgPath from goods";
        return queryForList(Goods.class,sql);
    }



    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from goods";

        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public List<Goods> queryForPageItems(int begin, int pageSize) {
        String sql = "select `id` , `name` , `kind` , `price` , `sales` , `img_path` imgPath from goods limit ?,?";
        return queryForList(Goods.class,sql,begin,pageSize);

    }

    @Override
    public Integer queryForPageTotalCountByPrice(int min, int max) {
        String sql = "select count(*) from goods where price between ? and ?";

        Number count = (Number) queryForSingleValue(sql,min,max);
        return count.intValue();
    }

    @Override
    public List<Goods> queryForPageItemsByPrice(int begin, int pageSize, int min, int max) {
        String sql = "select `id` , `name` , `kind` , `price` , `sales` , `img_path` imgPath from goods where price between ? and ? order by price limit ?,?";
        return queryForList(Goods.class,sql,min,max,begin,pageSize);
    }
}
